package com.yugao.fintech.antelope.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yugao.fintech.antelope.system.model.rqrs.microapp.MicroAppPageReq;
import com.yugao.fintech.antelope.system.model.rqrs.microapp.MicroAppResp;
import com.yugao.fintech.antelope.system.model.rqrs.microapp.MicroAppSaveReq;
import com.yugao.fintech.antelope.system.model.rqrs.microapp.MicroAppUpdateReq;
import com.yugao.fintech.antelope.system.service.SysMicroAppService;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 微应用(目前为实验性功能, 需要深入探索)
 */
@Api(tags = "微应用")
@RestController
@RequestMapping("/microApp")
public class SysMicroAppController {
    @Autowired
    private SysMicroAppService microAppService;

    @ApiOperation(value = "分页微应用")
    @GetMapping("/pageMicroApp")
    public Resp<IPage<MicroAppResp>> pageMicroApp(@Validated MicroAppPageReq req) {
        return Resp.ok(microAppService.pageMicroApp(req));
    }

    @ApiOperation(value = "通过id查找微应用")
    @GetMapping("/getMicroApp")
    public Resp<MicroAppResp> getMicroApp(@RequestParam(value = "id") Long id) {
        return Resp.ok(microAppService.getMicroApp(id));
    }
  
    @ApiOperation(value = "保存微应用")
    @PostMapping("/saveMicroApp")
    public Resp<?> saveMicroApp(@Validated @RequestBody MicroAppSaveReq req) {
        return Resp.ok(microAppService.saveMicroApp(req));
    }
  
    @ApiOperation(value = "更新微应用")
    @PostMapping("/updateMicroApp")
    public Resp<?> updateMicroApp(@Validated @RequestBody MicroAppUpdateReq req) {
        return Resp.ok(microAppService.updateMicroApp(req));
    }
  
    @ApiOperation(value = "批量删除微应用")
    @DeleteMapping("/batchDeleteMicroApp")
    public Resp<?> batchDeleteMicroApp(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(microAppService.batchDeleteMicroApp(ids));
    }
  
    @ApiOperation(value = "删除微应用")
    @DeleteMapping("/deleteMicroApp")
    public Resp<?> deleteMicroApp(@RequestParam(value = "id") Long id) {
        return Resp.ok(microAppService.deleteMicroApp(id));
    }
}
